﻿using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Organ.API.Application.SleepWeightCommands;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace FarmSmartSleep.Organ.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SleepWeightController : ControllerBase
    {
        private readonly IMediator mediator;

        public SleepWeightController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        #region 羊只称重
        /// <summary>
        /// 称重类型下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> GetSleepType()
        {
            return await mediator.Send(new WeightTypeSearchCommand());
        }
        /// <summary>
        /// 羊只称重添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddSleepWeight(SleepWeightCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 查询羊只称重列表
        /// </summary>
        /// <param name="StartDate"></param>
        /// <param name="EndDate"></param>
        /// <param name="EarNumber"></param>
        /// <param name="WeightType"></param>
        /// <param name="VarietyId"></param>
        /// <param name="Gender"></param>
        /// <param name="MonthMin"></param>
        /// <param name="MonthMax"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultT<SleepWeightDto>> GetSleepWeight(DateTime? StartDate, DateTime? EndDate, string ?EarNumber, int WeightType, int VarietyId, int Gender, decimal MonthMin, decimal MonthMax)
        {
            return await mediator.Send(new SleepWeightSearchCommand() { StartDate = StartDate, EndDate = EndDate, EarNumber = EarNumber, WeightType = WeightType, VarietyId = VarietyId, Gender = Gender, MonthMin = MonthMin, MonthMax = MonthMax });
        }
        #endregion
        #region 体尺测定
        /// <summary>
        /// 体尺添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddBodyMean(BodyMeanCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 体尺列表
        /// </summary>
        /// <param name="EarNumber"></param>
        /// <param name="VarietyId"></param>
        /// <param name="Gender"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultT<BodyMeanDto>> SearchBodyMean(string?EarNumber,int VarietyId,int Gender)
        {
            return await mediator.Send(new BodyMeanSearchCommand() { EarNumber=EarNumber, VarietyId=VarietyId,Gender= Gender });
        }
        #endregion
        #region 品相测定
        /// <summary>
        /// 品相测定添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddPhase(PhaseCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 品相测定列表
        /// </summary>
        /// <param name="EarNumber"></param>
        /// <param name="VarietyId"></param>
        /// <param name="Gender"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultT<PhaseDtos>> GetPhase(string? EarNumber,int VarietyId,int Gender)
        {
            return await mediator.Send(new PhaseSearchCommand() { EarNumber=EarNumber,VarietyId=VarietyId,Gender=Gender});
        }
        #endregion
    }
}
